package com.ti.winona.ui.fragment;

import com.loopj.android.image.SmartImageView;
import com.taplinker.client.AppConfigFactory;
import com.taplinker.client.R;
import com.ti.winona.net.API;
import com.ti.winona.util.FragmentOperateUtil;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class PerCenterFragment extends Fragment {
	
	public static final String TAG = "PerCenterFragment";
	
	private View mPerCenterView;
	
	private ImageView mImgPerCenterBack;
	
	private SmartImageView mImgPerCenterCustomer;
	private TextView mTxtPerCenterName;
	private TextView mTxtPerCenterCertificate;
	private TextView mTxtPerCenterCode;
	private TextView mTxtPerCenterHospital;
	private TextView mTxtPerCenterPhone;
	private TextView mTxtPerCenterEmail;
	private TextView mTxtPerCenterSex;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return mPerCenterView = inflater.inflate(R.layout.fragment_percenter, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		findView();
		init();
		initListener();
	}
	
	private void findView() {
		mImgPerCenterBack = (ImageView) mPerCenterView.findViewById(R.id.img_percenter_back);
		
		mImgPerCenterCustomer = (SmartImageView) mPerCenterView.findViewById(R.id.img_percenter_customer);
		mTxtPerCenterName = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_name);
		mTxtPerCenterCertificate = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_certificate);
		mTxtPerCenterCode = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_code);
		mTxtPerCenterHospital = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_hospital);
		mTxtPerCenterPhone = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_phone);
		mTxtPerCenterEmail = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_email);
		mTxtPerCenterSex = (TextView) mPerCenterView.findViewById(R.id.txt_percenter_sex);
	}
	
	private void init() {
		mImgPerCenterCustomer.setImageUrl(API.IMAGE + AppConfigFactory.getInstance().getUserInfo().getUserIcon());
		mTxtPerCenterName.setText(AppConfigFactory.getInstance().getUserInfo().getNickname());
		mTxtPerCenterCertificate.setText(AppConfigFactory.getInstance().getUser().getExpert().getPhysicianCertificate());
		mTxtPerCenterCode.setText(AppConfigFactory.getInstance().getUser().getExpert().getIdentification());
		mTxtPerCenterHospital.setText(AppConfigFactory.getInstance().getUser().getHospitalInfo().getName());
		mTxtPerCenterPhone.setText(AppConfigFactory.getInstance().getUser().getExpert().getPhone());
		mTxtPerCenterEmail.setText(AppConfigFactory.getInstance().getUser().getExpert().getMail());
		mTxtPerCenterSex.setText(AppConfigFactory.getInstance().getUser().getExpert().getSexual());
	}
	
	private void initListener() {
		// 返回监听
		mImgPerCenterBack.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				FragmentOperateUtil.popFragmentBackStack(getActivity().getSupportFragmentManager());
			}
		});
	}

}
